﻿using System;
using System.Collections.Generic;
using System.Text;
using FtpLib;
using System.Configuration;


namespace FileDownload
{
    public class ECSSDownloader
    {
        public void DownloadBOSSFile()
        {
            var ftpserver = ConfigurationManager.AppSettings["ftpserver"];
            var user = ConfigurationManager.AppSettings["user"];
            var password = ConfigurationManager.AppSettings["password"];
            var remoteBOSSLogPath = ConfigurationManager.AppSettings["RemoteBOSSLogPath"];

            using (FtpConnection ftp = new FtpConnection(ftpserver, user, password))
            {

                ftp.Open(); /* Open the FTP connection */
                ftp.Login(); /* Login using previously provided credentials */

                if (ftp.DirectoryExists(remoteBOSSLogPath)) /* check that a directory exists */
                    ftp.SetCurrentDirectory(remoteBOSSLogPath); /* change current directory */

                foreach (var dir in ftp.GetDirectories("/ECSS/BOSSLog"))
                {
                    Console.WriteLine(dir.Name);
                    Console.WriteLine(dir.CreationTime);
                    foreach (var file in dir.GetFiles())
                    {
                        Console.WriteLine(file.Name);
                        Console.WriteLine(file.CreationTime);
                        ftp.GetFile(ftp.GetCurrentDirectory() + "//" + dir.Name + "//" + file.Name, ConfigurationManager.AppSettings["LocalBOSSLogPath"] + file.Name, false);
                    }
                }
            }
        }

        public void UploadBOSSFile()
        {

        }
    }
}
